package testCases;
import static org.junit.Assert.*;

import org.junit.Test;

import Code.CalcStatistics;


public class TestCalcStatistics {

	@Test
	public void testHit() 
	{
		double trueHit = 0.97;
		double trueMiss = 0.9;
		double oldProb = 0.9;
		
		double bel = CalcStatistics.calcBeliefOcc(oldProb, true, trueHit, trueMiss);
		double bel1 = trueHit*oldProb;
		double bel2 = (1-trueMiss)*(1 - oldProb);
		double sum = bel1 + bel2;
		bel1 /= sum;
		assertEquals(bel, bel1, 0.0001);
		
		oldProb = 0.2;
		
		bel = CalcStatistics.calcBeliefOcc(oldProb, true, trueHit, trueMiss);
		bel1 = trueHit*oldProb;
		bel2 = (1-trueMiss)*(1 - oldProb);
		sum = bel1 + bel2;
		bel1 = bel1/sum;
		assertEquals(bel, bel1, 0.0001);
	}
	
	@Test
	public void testMiss()
	{
		double trueHit = 0.9;
		double trueMiss = 0.6;
		double oldProb = 0.9;
		
		double bel = CalcStatistics.calcBeliefOcc(oldProb, false, trueHit, trueMiss);
		double bel1 = (1-trueHit)*oldProb;
		double bel2 = trueMiss*(1 - oldProb);
		double sum = bel1 + bel2;
		bel1 = bel1/sum;
		assertEquals(bel, bel1, 0.0001);
		
		oldProb = 0.2;
		
		bel = CalcStatistics.calcBeliefOcc(oldProb, false, trueHit, trueMiss);
		bel1 = (1-trueHit)*oldProb;
		bel2 = trueMiss*(1 - oldProb);
		sum = bel1 + bel2;
		bel1 = bel1/sum;
		assertEquals(bel, bel1, 0.0001);
	}

}
